import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:homemedia/model/enum/MediaType.dart';
import 'package:homemedia/model/media.dart';
import 'package:homemedia/page/route_config.dart';
import 'package:homemedia/page/widget/loading_widget.dart';
import 'package:uuid/uuid.dart';
import 'package:flutter_animate/flutter_animate.dart';

class VideoCard extends StatelessWidget {
  final String img;
  final MediaLibrary entry;

  VideoCard({
    super.key,
    required this.img,
    required this.entry,
  });

  static const uuid = Uuid();
  final String imgTag = uuid.v4();
  final String titleTag = uuid.v4();
  final String authorTag = uuid.v4();

  @override
  Widget build(BuildContext context) {

    return Focus(
      onKeyEvent: (node, event) {
        return KeyEventResult.ignored;
      },
      child: Builder(
        builder: (context) {
          FocusNode node = Focus.of(context);
          return SizedBox(
            width: node.hasFocus ? 400:380.0,
            height: node.hasFocus ? 230:215,
            child: Card(
              shape: const RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(10.0)),
              ),
              elevation: node.hasFocus ? 5.0:4.0,
              shadowColor: node.hasFocus ? const Color.fromARGB(255, 85, 210, 255) : null,
              child: InkWell(
                borderRadius: const BorderRadius.all(Radius.circular(10.0)),
                onTap: () {
                  // final bool isHomeTab =
                  //     ref.read(currentTabNotifierProvider).isHomeTab;
                  // final route = BookDetailsRoute(
                  //   entry: entry,
                  //   imgTag: imgTag,
                  //   titleTag: titleTag,
                  //   authorTag: authorTag,
                  // );
                  //
                  // if (context.isLargeScreen && isHomeTab) {
                  //   context.router.replace(route);
                  // } else {
                  //   context.router.push(route);
                  // }
                  Get.toNamed(RouteConfig.library, arguments: {"uuid": entry.uuid, "source": 1});

                },
                child: ClipRRect(
                  borderRadius: const BorderRadius.all(
                    Radius.circular(10.0),
                  ),
                  child: Hero(
                    tag: imgTag,
                    child: CachedNetworkImage(
                      imageUrl: img,
                      placeholder: (context, url) => const LoadingWidget(
                        isImage: true,
                      ),
                      errorWidget: (context, url, error) => Image.asset(
                        'assets/images/place.png',
                        fit: BoxFit.cover,
                      ),
                      fit: BoxFit.cover,
                    ),
                  ),
                ),
              ),
            ),
          ).animate().scale(duration: 500.ms, alignment: Alignment.centerLeft);
        },
      )
    );
  }
}
